package se.teamscape.client.view;

import se.teamscape.client.presenter.BaseContainerPresenter;
import se.teamscape.client.presenter.BaseContainerPresenter.WidgetProperties;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A basic container view implementation.
 * 
 * @author Andreas Borglin
 * 
 */
public class BasicContainerView extends BaseView implements BaseContainerPresenter.Display {

    private FlowPanel mPanel;
    private boolean mSingleWidget = false;
    private boolean mHorizontal = false;

    public BasicContainerView() {
    }

    protected void setSingleWidget(boolean single) {
        mSingleWidget = single;
    }

    protected void setHorizontalFlow() {
        mHorizontal = true;
    }

    @Override
    public void init() {
        mPanel = new FlowPanel();

        if (mHorizontal) {
            mPanel.setStyleName("HorizontalFlow");
        }
    }

    @Override
    public void removeWidget(Widget widget) {
        mPanel.remove(widget);
    }

    @Override
    public void showWidget(Widget widget, WidgetProperties properties) {
        if (mSingleWidget && mPanel.getWidgetCount() > 0) {
            mPanel.clear();
        }
        mPanel.add(widget);
    }

    @Override
    public Widget asWidget() {
        return mPanel;
    }

    @Override
    public void removeAll() {
        mPanel.clear();
    }

}
